<!--  -->
<template>
  <div class="pay-confirm">
    <Nav title="支付完成">
      <template v-slot:left>
        <span class="back-icon" @click="$router.back()"></span>
      </template>
    </Nav>
    <div class="bg" :class="confirmDetail.show_toast.is_show?'':'bg-198'"></div>
    <div class="option-wrap flex justify-center">
      <router-link tag="span" to="/index/home" class="option flex justify-center aligin-center">返回首页</router-link>
      <router-link
        tag="span"
        to="/index/order"
        class="option_ flex justify-center aligin-center"
        v-if="!$route.query.from"
      >查看订单</router-link>
    </div>
    <div class="record">活动号码可前往【参与记录】查看</div>
    <div class="order-list">券码可前往【订单】页面查看</div>
    <div class="count-add flex aligin-center justify-center" v-if="confirmDetail.show_toast.is_show">
      <span class="lucky">恭喜您~</span>
      <span>
        本单获得了
        <span class="color-orange">{{confirmDetail.show_toast.c}}次</span>
        0元抢购机会
      </span>
    </div>
    <div class="body" :class="confirmDetail.show_toast.is_show?'':'body-198'">
      <div class="count-wrap flex aligin-center" v-if="confirmDetail.lyg.length">
        <span>【0元购】您还可免费参与：{{confirmDetail.num}}次</span>
        <span class="add-btn flex aligin-center" @click="shareFlag=true">增加</span>
      </div>
      <div class="product-list flex justify-between">
        <template v-for="(item,index) in confirmDetail.lyg">
          <router-link
            tag="div"
            class="order-item"
            :key="index"
            :to="{name:'detail',params:{id:item.id}}"
          >
            <img class="product-img" :src="item.image" alt />
            <div class="product-name ellipsis-line2">{{item.name}}</div>
            <div class="flex justify-between">
              <span class="price">￥0.00</span>
              <span class="go flex justify-center aligin-center">前往</span>
            </div>
          </router-link>
        </template>
      </div>
      <div class="count-wrap" v-if="confirmDetail.hd.length">【为你推荐】</div>
      <div class="product-list flex justify-between">
        <template v-for="(item,index) in confirmDetail.hd">
          <router-link
            tag="div"
            class="order-item"
            :key="index"
            :to="{name:'detail',params:{id:item.id}}"
          >
            <img class="product-img" :src="item.image" alt />
            <div class="product-name ellipsis-line2">{{item.name}}</div>
          </router-link>
        </template>
      </div>
    </div>
    <div class="info" v-if="showMask">
      <div class="J-weixin-tip weixin-tip">
        <div class="weixin-tip-content">请在菜单中选择分享</div>
      </div>
      <div class="btn flex justify-center aligin-center" @click="showMask=false">我知道了</div>
    </div>
    <ShareDialog
      :info="confirmDetail.reward"
      :shareFlag.sync="shareFlag"
      @closeAds="shareFlag=false"
      @shareActivity="shareActivity"
    ></ShareDialog>
  </div>
</template>

<script>
import Nav from '../../components/Nav'
import ShareDialog from '../../components/countLint_'
import { pay_success } from '../../api/api'
export default {
  components: { Nav, ShareDialog },
  data() {
    return {
      shareFlag: false,
      confirmDetail: { lyg: [], hd: [],show_toast:{} },
      showMask: false //显示指引
    }
  },
  computed: {},
  watch: {},
  methods: {
    _shareConfig(jsk) {
      wx.config(jsk)
      wx.ready(() => {
        wx.updateTimelineShareData({
          title: '融媒优品', // 分享标题
          link:
            window.location.origin +
            `/shareRegister?pid=${this.confirmDetail.uid}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: 'https://cdn.weile999.com/ygp_v2/logo/logo.png', // 分享图标
          success: function(res) {
            // 设置成功
            console.log('success', res)
          },
          fail: function(res) {
            console.log('fail', res)
          }
        })
        wx.updateAppMessageShareData({
          title: '融媒优品', // 分享标题
          link:
            window.location.origin +
            `/shareRegister?pid=${this.confirmDetail.uid}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          desc: '兰溪官方特色购物平台。', // 分享描述
          imgUrl: 'https://cdn.weile999.com/ygp_v2/logo/logo.png', // 分享图标
          success: function(res) {
            // 设置成功
            console.log('success', res)
          },
          fail: function(res) {
            console.log('fail', res)
          }
        })
        // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
      })
      wx.error(res => {})
    },
    // 分享
    shareActivity() {
      var ua = navigator.userAgent.toLowerCase()
      var isWeixin = ua.indexOf('micromessenger') != -1
      if (isWeixin) {
        this.showMask = true
      } else {
        this.$copyText(
          window.location.origin +
            window.location.pathname +
            '?pid=' +
            this.confirmDetail.uid
        ).then(
          e => {
            this.$toast('复制成功！')
          },
          e => {
            this.$notify(e)
          }
        )
      }
    }
  },
  created() {},
  mounted() {
    pay_success().then(({ data: { result } }) => {
      this.confirmDetail = result
      this._shareConfig(result.jsk)
    })
  },
  updated() {}, //生命周期 - 更新之后
  destroyed() {} //生命周期 - 销毁完成
}
</script>
<style lang='less' scoped>
@import url('../../assets/style/mixin');
.pay-confirm /deep/ .nav {
  position: relative;
  color: #fff;
  z-index: 100;
}
.pay-confirm {
  position: relative;
  height: 100%;
  .bg {
    position: absolute;
    height: 245px;
    width: 100%;
    top: 0;
    left: 0;
    background: linear-gradient(66deg, #e83038, #f75897);
  }
  .bg-198{
    height: 158px;
  }
 
  .back-icon {
    display: inline-block;
    width: 22px;
    height: 22px;
    background: url('../../assets/imgs/arrow-left-w.png');
    background-size: 100% 100%;
  }
  .option-wrap {
    position: relative;
    margin-top: 6px;
    z-index: 2;
    .option {
      color: #fff;
      width: 80px;
      height: 24px;
      border: 1px solid rgba(255, 255, 255, 1);
      border-radius: 12px;
    }
    .option_ {
      margin-left: 20px;
      color: #fff;
      width: 80px;
      height: 24px;
      border: 1px solid rgba(255, 255, 255, 1);
      border-radius: 12px;
    }
  }
  .record {
    position: relative;
    z-index: 2;
    margin-top: 18px;
    font-size: 12px;
    color: #fff;
    text-align: center;
  }
  .order-list {
    position: relative;
    z-index: 2;
    font-size: 12px;
    color: #fff;
    margin-top: 5px;
    text-align: center;
  }
  .count-add {
    position: relative;
    z-index: 2;
    margin: 27px auto 0;
    flex-direction: column;
    width: 313px;
    height: 69px;
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
  }
  .color-orange{
    color: #F76F44;
  }
  .lucky{
    margin-bottom: 14px;
    font-size: 18px;
    color: #F76F44;
  }
  .tip {
    position: relative;
    z-index: 100;
    font-size: 12px;
    text-align: center;
    line-height: 18px;
    color: #fff;
  }
  .body {
    margin-top: 10px;
    padding-top: 12px;
    height: calc(100% - 245px);
    box-sizing: border-box;
    overflow-y: auto;
    .count-wrap {
      margin-top: 25px;
      font-size: 14px;
      text-indent: 5px;
      .add-btn {
        margin-left: 8px;
        width: 35px;
        height: 19px;
        border: 1px solid rgba(245, 79, 117, 1);
        border-radius: 5px;
        color: #ef4366;
      }
    }
    .product-list {
      margin-top: 20px;
      padding: 0 16px;
      flex-wrap: wrap;
    }
    .order-item {
      margin-bottom: 16px;
      padding: 7px;
      width: 168px;
      background: rgba(255, 255, 255, 1);
      border: 1px solid rgba(221, 221, 221, 1);
      border-radius: 8px;
      box-sizing: border-box;
      .product-img {
        width: 100%;
        height: 125px;
      }
      .product-name {
        margin-bottom: 14px;
        font-size: 13px;
        line-height: 15px;
        height: 30px;
      }
      .price {
        color: #e83038;
        font-size: 14px;
      }
      .go {
        width: 48px;
        height: 15px;
        background: linear-gradient(
          270deg,
          rgba(232, 48, 56, 1),
          rgba(247, 88, 151, 1)
        );
        border-radius: 7px;
        color: #fff;
      }
    }
  }
  .body-198{
    height: calc(100% - 158px);
  }
  .tip-1 {
    margin-top: 30px;
    font-size: 12px;
    text-align: center;
    color: #686868;
  }
  .back-btn {
    margin: 20px auto 10px;
    width: 301px;
    height: 45px;
    border: 1px solid rgba(209, 209, 209, 1);
    border-radius: 23px;
    font-size: 15px;
    text-align: center;
    line-height: 45px;
    color: #686868;
  }
  .order-check {
    margin: 0 auto;
    width: 301px;
    height: 45px;
    background: rgba(232, 48, 56, 1);
    border-radius: 23px;
    font-size: 15px;
    text-align: center;
    line-height: 45px;
    color: #fff;
  }
  .info {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
  }
  .btn {
    color: #fff;
    margin: 10px auto;
    width: 70px;
    height: 25px;
    border-radius: 5px;
    border: 1px dashed #fff;
  }
  .weixin-tip-content {
    font-size: 16px;
    letter-spacing: 5px;
    font-weight: bold;
    line-height: 20px;
  }
  .weixin-tip {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #fff;
    width: 265px;
    padding: 55px 0 0;
    margin: 0 auto;
    text-align: center;
    background: url()
      no-repeat right top;
    background-size: 45px 68px;
  }

  .weixin-tip-img {
    padding: 110px 0 0;
  }

  .weixin-tip-img::after {
    display: block;
    margin: 15px auto;
    content: ' ';
    background-size: cover;
  }
}
</style>